package org.coderead.calculator;

import com.sun.xml.internal.ws.util.StringUtils;
import org.coderead.model.Performance;

public abstract class AbstractPerformanceCalculator {
    public abstract int getAmount(Performance performance);

    public abstract double getVolumeCredit(Performance performance);

    public static AbstractPerformanceCalculator of(String playType) {
        try {
            return (AbstractPerformanceCalculator) Class.forName(getClassName(playType)).newInstance();
        } catch (Exception e) {
            throw new RuntimeException("unknown type:" + playType);
        }
    }

    private static String getClassName(String playType) {
        return String.format("%s.%sCalculator", getPackageName(), StringUtils.capitalize(playType));
    }

    private static String getPackageName() {
        return AbstractPerformanceCalculator.class.getPackage().getName();
    }
}
